package com.hoas.comparedb.pojo;

import com.hoas.comparedb.entity.TableIndex;
import com.hoas.comparedb.util.StrTool;

public class TableIndexDiffItem extends DiffItem<TableIndex> {

    public static final String NO = "NO";
    public static final String ADD = "ADD";
    public static final String DROP = "DROP";
    public static final String MODIFY = "MODIFY";

    public TableIndexDiffItem(TableIndex ot, TableIndex nt) {
        super(ot, nt);

        if (ot == null && nt != null ) {
            setType(ADD);

        } else if(ot != null && nt == null) {
            // 删除字段
            setType(DROP);
            setKey( ot.getIndexName() );

        } else if (ot.getIndexName().equals(nt.getIndexName())) {
            // 修改字段
            setType(MODIFY);
            setKey( ot.getIndexName() );

            if (
                    StrTool.equals(ot.getCompositIndex(), nt.getCompositIndex())
                            && StrTool.equals(ot.getIndexType(), nt.getIndexType())
                            && ot.getNonUnique().equals( nt.getNonUnique())
            ) {
                setType( NO );
            }

        }



    }

}
